/**
 * 功能描述
 */

define(function (require, exports, module) {
	var Component = require("grid");
	var Dialog=require("dialog");
	var aw = require("ajaxwrapper");
	var fetchProperties = require("../constant/fetchProperties");
	var gridEvents = require("../handler/gridEvents");
    var instance = {
        initComponent : function (params, widget) {
            var component = new Component({
            	parentNode : ".J-grid",
            	autoRender:false,
            	url : "api/checkinimplement/waterelectricgroup",
            	params : function(){
					var subnav = widget.get("subnav");
					var obj = {
						//"room.orgBuilding.pkOrgBuilding" : subnav.getValue("orgBuilding"),
						//"room.pkRoom" : subnav.getValue("room"),
						"checkInStatus" : subnav.getValue("checkInStatus"),
						"pkServicePoint" : subnav.getValue("servicePoint"),
						"startDate" : subnav.getValue("checkInDate").start,
						"endDate" : subnav.getValue("checkInDate").end,
						fetchProperties:fetchProperties.gridFetchProperties
					};
	    			return obj;
				},
				model : {
				 columns  : [{
					 name : "checkInImplement.groupReserve.reserveDate",//operateDate
					 label : "预约日期",
					 format :function(value,row){
						 if(!value){
							 return moment(row.checkInImplement.nonMemGroupReserve.nonMemberGroup.operateDate).format("YYYY-MM-DD");
						 }else{
							 return moment(row.checkInImplement.groupReserve.reserveDate).format("YYYY-MM-DD");
						 }
					 },
				 },{
					 name : "checkInImplement.groupReserve.planItemGroup.allianceOrg.name",
					 label : "组团单位/预约人",
					format: function(value,row){
    						if(value){
    							return row.checkInImplement.groupReserve.planItemGroup.allianceOrg.name;
    						}else if(row.checkInImplement.groupReserve){
    							return row.checkInImplement.groupReserve.planItemGroup.servicePoint.name;
    						}else{
    							return row.checkInImplement.nonMemGroupReserve.nonMemberGroup.contactName;
    						}
    				}
				 },{
					 name : "checkInImplement.groupReserve.planItemGroup.planItem.destination.name",
					 label : "目的地",
					 format :function(value,row){
						 if(value){
							 return row.checkInImplement.groupReserve.planItemGroup.planItem.destination.name;
						 }else{
							 return row.checkInImplement.nonMemGroupReserve.nonMemberGroup.servicePoint.name;
						 }
					 },
				 },{
					 name : "checkInImplement.groupReserve.checkInDate",
					 label : "入住日期",
					 format :function(value,row){
						 if(value){
							 return moment(row.checkInImplement.groupReserve.checkInDate).format("YYYY-MM-DD");
						 }else{
							 return moment(row.checkInImplement.nonMemGroupReserve.nonMemberGroup.checkInDate).format("YYYY-MM-DD");
						 }
					 },
				 },{
					 name : "checkInImplement.groupReserve.checkOutDate",
					 label : "退住日期",
					 format :function(value,row){
						 if(value){
							 return moment(row.checkInImplement.groupReserve.checkOutDate).format("YYYY-MM-DD");
						 }else{
							 return moment(row.checkInImplement.nonMemGroupReserve.nonMemberGroup.checkOutDate).format("YYYY-MM-DD");
						 }
					 },
				 },{
					 name : "checkInImplement.groupReserve.roomNum",
					 label : "房间数",
					 format :function(value,row){
						 if(value){
							 return row.checkInImplement.groupReserve.roomNum;
						 }else{
							 return row.roomCount;
						 }
					 },
				 },{
					 name : "checkInStatus.value",
					 label : "状态",
				 },{
					 name : "operate",
					 label : "操作",
					 format:"button",
						formatparams:[{
							id:"checkIn",
							text:"入住抄表",
							show:function(value,data){
								if(data.checkInStatus.key == "NoCheckIn"){
									return true;
								}else{
									return false;
								}
							},
							handler:function(index,data,rowEle){
								if(data.checkInStatus.key == "NoCheckIn"){
									gridEvents.EnterMeter(data,widget);
								}else{
									Dialog.alert({
				                		title:"提示",
				                		content:"该状态下不能进行入住抄表！"
				                	});
									return false;
								}
							}
						},{
							id:"checkOut",
							text:"退住抄表",
							show:function(value,data){
								if(data.checkInStatus.key == "CheckIn"){
									return true;
								}else{
									return false;
								}
							},
							handler:function(index,data,rowEle){
								if(data.checkInStatus.key == "CheckIn"){
									gridEvents.EnterMeter(data,widget);
								}else{
									Dialog.alert({
				                		title:"提示",
				                		content:"该状态下不能进行退住抄表！"
				                	});
									return false;
								}
							
							}
						},{
							id:"search",
							text:"查看",
							show:function(value,data){
								if(data.checkInStatus.key != "CheckIn"&&data.checkInStatus.key != "NoCheckIn"){
									return true;
								}else{
									return false;
								}
							},
							handler:function(index,data,rowEle){
									gridEvents.EnterMeter(data,widget);
							}
						}]
				 }]
				}
            });
            widget.set("grid", component);
        }
    };
    module.exports = instance;
});
